#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import Context
from django.template.loader import get_template
from cupblog.config.server import DEFAULT_THEME
from cupblog.func import set_template_dir

__author__ = 'lihaoquan'

#获取信息然后进行普通的HttpResponse
def getInfoHttpResponse(request, template, d):

    current_theme = DEFAULT_THEME

    d['host'] = request.get_host()
    d['user'] = request.session.get('user')
    d['theme'] = current_theme

    set_template_dir('themes', current_theme)
    t= get_template(template)
    html = t.render(Context(d))
    return HttpResponse(html)


#获取信息然后以admin进行httpResponse
def getInfoAdminHttpResponse(request, template, d):
    t= get_template(template)
    html = t.render(Context)
    return HttpResponse(html)


#进行重定向
def go_redirect(request, title, path=None, delay=200):
    set_template_dir('admin')
    if path is None:
        path = request.get_full_path()[1:]
    return render_to_response('redirect.html', {
        'host':request.get_host(),
        'title': title,
        'redirect': path,
        'delay': delay,
        })
